package com.hbvtc.xxxy.nikeSale.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbManager {
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://localhost:3306/nike";
	private static final String USERNAME= "root";
	private static final String PASSSWORD = "zhao010106";
	private static Connection conn = null;

	// 加载驱动
	static {
		try {
			Class.forName(DRIVER);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// 数据库连接
	public static Connection getconn() {
		try {
			conn=DriverManager.getConnection(URL, USERNAME, PASSSWORD);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}

	// 关闭数据库
	public static Connection closeconn() {
		try {
			conn=DriverManager.getConnection(URL, USERNAME, PASSSWORD);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}

	public static void main(String[] args) {
		Connection conn = getconn();
		if (conn != null) {
			System.out.println("数据库连接成功....");
		} else {
			System.out.println("数据库连接失败...");
		}
	}
}
